<!DOCTYPE html>
<html>
  
  <head>
      <meta charset="UTF-8">
      <title>欢迎页面-X-admin2.0</title>
      <meta name="renderer" content="webkit">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
      <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
      <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
      <link rel="stylesheet" href="/static/css/font.css">
      <link rel="stylesheet" href="/static/css/xadmin.css">
      <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
      <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
      <script type="text/javascript" src="/static/js/xadmin.js"></script>
      <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
      <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
      <![endif]-->

      <link rel="stylesheet" href="/static/sweetalert/sweetalert.css">
      <script src="/static/sweetalert/ions_alert.js"></script>
      <script src="/static/sweetalert/sweetalert.min.js"></script>
  </head>
  
  <body>
    <div class="x-body">
        <form class="layui-form">
          <div class="layui-form-item">
              <label for="L_email" class="layui-form-label">
                  <span class="x-red">*</span>用户名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="username" name="username" lay-verify="username"
                  autocomplete="off" class="layui-input" value="{{.user.UserName}}">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>将会成为您唯一的登入名(必填)
              </div>
          </div>
            <div class="layui-form-item">
                <label for="L_nickname" class="layui-form-label">
                    <span class="x-red">*</span>工号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="job_id" name="job_id" lay-verify="job_id"
                           autocomplete="off" class="layui-input" value="{{.user.JobId}}">
                </div>
            </div>
          <div class="layui-form-item">
              <label for="L_nickname" class="layui-form-label">
                  <span class="x-red">*</span>昵称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="nickname" name="nickname" lay-verify="nickname"
                  autocomplete="off" class="layui-input" value="{{.user.NickName}}">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_pass_word" class="layui-form-label">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="pass_word" name="pass_word" lay-verify="password"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux"> 密码长度为6到16个字符或数字
              </div>
          </div>
            <div class="layui-form-item">
                <label for="L_age" class="layui-form-label">
                    <span class="x-red">*</span>年龄
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="age" name="age"  lay-verify="required"
                           autocomplete="off" class="layui-input" value="{{.user.Age}}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_gender" class="layui-form-label">
                    <span class="x-red">*</span>性别
                </label>
                <div class="layui-input-inline" style="width: 220px">
                    {{if eq .user.Gender 1}}
                        <input type="radio" name="gender" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="1" title="男" checked>
                        <input type="radio" name="gender" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="2" title="女">
                        <input type="radio" name="gender" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="3" title="未知">

                    {{else if eq .user.Gender 2}}
                        <input type="radio" name="gender" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="1" title="男">
                        <input type="radio" name="gender" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="2" title="女" checked>
                        <input type="radio" name="gender" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="3" title="未知">

                    {{else if eq .user.Gender 3}}
                        <input type="radio" name="gender" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="1" title="男">
                        <input type="radio" name="gender" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="2" title="女">
                        <input type="radio" name="gender" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="3" title="未知" checked>
                    {{end}}
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_phone" class="layui-form-label">
                    <span class="x-red">*</span>手机号码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="phone" name="phone" lay-verify="phone"
                           autocomplete="off" class="layui-input" value="{{.user.Phone}}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_addr" class="layui-form-label">
                    <span class="x-red">*</span>联系地址
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="addr" name="addr" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{{.user.Addr}}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    <span class="x-red">*</span>邮件
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="email" name="email"  lay-verify="required"
                           autocomplete="off" class="layui-input" value="{{.user.Email}}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_card_id" class="layui-form-label">
                    <span class="x-red">*</span>身份证号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="card_id" name="card_id"  lay-verify="required"
                           autocomplete="off" class="layui-input" value="{{.user.CardId}}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_head_portrait" class="layui-form-label">
                    <span class="x-red">*</span>用户头像
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="head_portrait" name="head_portrait" required="" lay-verify=""
                           autocomplete="off" class="layui-input" value="{{.user.HeadPortrait }}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_is_active" class="layui-form-label">
                    <span class="x-red">*</span>启用状态
                </label>
                <div class="layui-input-inline">
                    {{if eq .user.IsActive 1}}
                        <input type="radio" name="is_active" autocomplete="off" class="layui-input" value="1" title="启用" checked>

                        <input type="radio" name="is_active" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="0" title="停用">
                    {{else if eq .user.IsActive 2}}
                        <input type="radio" name="is_active" autocomplete="off" class="layui-input" value="1" title="启用">

                        <input type="radio" name="is_active" required="" lay-verify="repass"
                               autocomplete="off" class="layui-input" value="0" title="停用" checked>
                    {{end}}
                </div>
            </div>

          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
{{/*              <input type="hidden" id="sys_id"  value="{{.user.SysId}}">*/}}
              <input type="hidden" value="{{.user.SysId}}" id="uid">
              <button  class="layui-btn" lay-filter="add" lay-submit type="button">
                  提交
              </button>
          </div>
      </form>
    </div>
    <script>
            $(function  () {
                layui.use('form', function () {
                    var form = layui.form;
                    //监听提交
                    form.on('submit(add)', function (data) {
                        // nickname 用的是 id="nickname"
                        var username = document.getElementById("username").value;
                        var job_id = document.getElementById("job_id").value;
                        var nickname = document.getElementById("nickname").value;
                        var pass_word = document.getElementById("pass_word").value;
                        var age = document.getElementById("age").value;
                        var gender = $("input[name='gender']:checked").val()
                        var phone = document.getElementById("phone").value;
                        var addr = document.getElementById("addr").value;
                        var email = document.getElementById("email").value;
                        var card_id = document.getElementById("card_id").value;
                        var head_portrait = document.getElementById("head_portrait").value;
                        var is_active = $("input[name='is_active']:checked").val();
                        var sys_id = document.getElementById("uid").value;

                        if (nickname.length<2){
                            alert("昵称长度不能小于2个字符！");
                            return
                        }
                        if (username.length<2){
                            alert("用户名称不能小于2个字符！");
                            return
                        }
                        $.ajax({
                            url:"{{urlfor "UserController.DoUpdate"}}",
                            type:"POST",
                            data:{
                                "sys_id":sys_id,
                                "job_id":job_id,
                                "username":username,
                                "nickname":nickname,
                                "pass_word":pass_word,
                                "age":age,
                                "gender":gender,
                                "phone":phone,
                                "addr":addr,
                                "email":email,
                                "card_id":card_id,
                                "head_portrait":head_portrait,
                                "is_active":is_active
                            },
                            success:function (data) {
                                var code = data["code"];
                                if (code == 200){
                                    ions_alert.alertSuccessToast(data["msg"]);
                                     setTimeout(reload_list,2000);  // 2s 显示时间2秒后刷新list页面
                                }else {
                                    ions_alert.alertErrorToast(data["msg"]);
                                }
                            },
                            fail:function (data) {
                                alert(data)
                            }
                        });
                        // 刷新list页面所用
                        function reload_list() {
                            // // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            window.location.href = "{{urlfor "UserController.List"}}"

                        }

                    });
                });
          
        })
    </script>
  </body>

</html>